package com.xueyi.workflow.controller;

import com.xueyi.common.core.web.result.AjaxResult;
import com.xueyi.common.core.web.validate.V_A;
import com.xueyi.common.core.web.validate.V_E;
import com.xueyi.common.log.annotation.Log;
import com.xueyi.common.log.enums.BusinessType;
import com.xueyi.common.security.auth.pool.WorkflowPool;
import com.xueyi.common.web.entity.controller.BaseController;
import com.xueyi.workflow.domain.dto.ProcessFormBindDto;
import com.xueyi.workflow.domain.query.ProcessFormBindQuery;
import com.xueyi.workflow.service.ProcessFormBindService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@Tag(name = "流程表单绑定管理")
@RestController
@RequestMapping("/processFormBind")
public class ProcessFormBindController extends BaseController<ProcessFormBindQuery, ProcessFormBindDto, ProcessFormBindService> {
    @Autowired
    private ProcessFormBindService baseService;

    @Override
    protected String getNodeName() {
        return "流程表单绑定";
    }

    @Operation(summary = "分页查询流程-表单绑定")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_PROCESS_FORM_BIND_LIST + "')")
    @GetMapping("/list")
    public AjaxResult list(ProcessFormBindQuery query) {
        return AjaxResult.success(baseService.selectBindListWithNames());
    }

    @Operation(summary = "查询流程-表单绑定详情")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_PROCESS_FORM_BIND_SINGLE + "')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Serializable id) {
        return super.getInfo(id);
    }

    @Operation(summary = "新增流程-表单绑定")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_PROCESS_FORM_BIND_ADD + "')")
    @PostMapping
    public AjaxResult add(@Validated({V_A.class}) @RequestBody ProcessFormBindDto dto) {
        return super.add(dto);
    }

    @Operation(summary = "修改流程-表单绑定")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_PROCESS_FORM_BIND_EDIT + "')")
    @PutMapping
    public AjaxResult edit(@Validated({V_E.class}) @RequestBody ProcessFormBindDto dto) {
        return super.edit(dto);
    }

    @Operation(summary = "批量删除流程-表单绑定")
    @PreAuthorize("@ss.hasAuthority('" + WorkflowPool.WORKFLOW_PROCESS_FORM_BIND_DEL + "')")
    @DeleteMapping("/batch/{idList}")
    public AjaxResult batchRemove(@PathVariable List<Long> idList) {
        return super.batchRemove(idList);
    }
}
